﻿Imports System
Imports System.ComponentModel
Imports System.Workflow.ComponentModel

Namespace System.Workflow.Activities
    <ProvideProperty("UnlessCondition", GetType(Activity)), ProvideProperty("WhenCondition", GetType(Activity))> _
    Friend NotInheritable Class ConditionPropertyProviderExtender
        Implements IExtenderProvider
        ' Methods
        Friend Sub New()
        End Sub

        Public Function CanExtend(ByVal extendee As Object) As Boolean
            Return (((Not extendee Is Me) AndAlso TypeOf extendee Is Activity) AndAlso TypeOf DirectCast(extendee, Activity).Parent Is ConditionedActivityGroup)
        End Function

        <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), SRCategory("ConditionedActivityConditions"), SRDescription("WhenConditionDescr")> _
        Public Function GetWhenCondition(ByVal activity As Activity) As ActivityCondition
            If TypeOf activity.Parent Is ConditionedActivityGroup Then
                Return [TryCast](activity.GetValue(ConditionedActivityGroup.WhenConditionProperty),ActivityCondition)
            End If
            Return Nothing
        End Function

        <SRCategory("ConditionedActivityConditions"), SRDescription("WhenConditionDescr")> _
        Public Sub SetWhenCondition(ByVal activity As Activity, ByVal handler As ActivityCondition)
            If TypeOf activity.Parent Is ConditionedActivityGroup Then
                activity.SetValue(ConditionedActivityGroup.WhenConditionProperty, handler)
            End If
        End Sub

    End Class
End Namespace

